package com.shigu.searchWord.action;

import com.shigu.MallResponse;
import com.shigu.PageResponse;
import com.shigu.exceptions.AdminException;
import com.shigu.searchWord.api.KeywordsService;
import com.shigu.searchWord.bo.DeleteIndexHotSearchWordRequest;
import com.shigu.searchWord.bo.IndexHotSearchWordRequest;
import com.shigu.searchWord.vo.IndexHotSearchWordList;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("adminjson")
public class KeyWordsAdminController {

    @Resource(name = "keywordsServiceImpl")
    KeywordsService keywordsService;

    @RequestMapping("setIndexHotSearchWord")
    @ResponseBody
    public MallResponse setIndexHotSearchWord(IndexHotSearchWordRequest request) throws AdminException {
        keywordsService.setOrUpdateHotWord(StringUtils.isBlank(request.getHotWordId()) ? null : Long.valueOf(request.getHotWordId()),
                request.getHotKeyword(), request.getWeight(), request.getColorVal());
        return new MallResponse().success();
    }

    @RequestMapping("getIndexHotSearchWord")
    @ResponseBody
    public PageResponse<IndexHotSearchWordList> getIndexHotSearchWord() {
        return keywordsService.getIndexHotSearchWord().success();
    }

    @RequestMapping("deleteIndexHotSearchWord")
    @ResponseBody
    public MallResponse deleteIndexHotSearchWord(DeleteIndexHotSearchWordRequest request) throws AdminException {
        keywordsService.deleteIndexHotSearchWord(request.getHotWordId());
        return new MallResponse().success();
    }
}
